package v1

import (
	"github.com/gin-gonic/gin"
	"go_blok/server/model/req"
	"go_blok/server/model/resp"
	"go_blok/server/service"
)

type UserAPI struct{}

func (u *UserAPI) Register(c *gin.Context) {
	var req req.RegisterReq
	err := c.ShouldBindJSON(&req)
	if err != nil {
		resp.FailWithError(err, c)
		return
	}
	// 注册
	err = service.ServerEnter.UserService.Register(req)
	if err != nil {
		resp.FailWithError(err, c)
		return
	}
	resp.OkWithMsg("账户注册成功", c)
}

//func (u *UserAPI) Login(c *gin.Context) {
//
//}

func (u *UserAPI) GetEmailCode(c *gin.Context) {
	var req req.RegisterReq
	err := c.ShouldBindJSON(&req)
	if err != nil {
		resp.FailWithError(err, c)
		return
	}
	_, err = service.ServerEnter.UserService.GetEmailCode(req.Email)
	if err != nil {
		return
	}
	resp.OkWithMsg("验证码发送成功", c)
}
